import React, { Component } from 'react';
import { Form, Input,Button,message } from 'antd';
import request from '../../utils/request';


const formItemLayout = {
    labelCol: { span: 6 },
    wrapperCol: { span: 14 },
};

export default class Registry extends Component {
    onFinish = (values) => {
        console.log(values);
        request.post('/api/registry',values).then(res => {
            if(res.data.code === 1){
                message.success('注册成功',1,() => {
                    this.props.history.push('/login');
                });
            }else{
                message.error(res.data.msg,1)
            }
        })
    }   
    render() {
        return (
            <Form
                name="basic"
                onFinish={this.onFinish}
                labelAlign="right"
                {...formItemLayout}
                >
                <Form.Item
                    label="Username"
                    name="username"
                    rules={[
                    {
                        required: true,
                        message: '请输入用户名',
                    },
                    ]}
                >
                    <Input />
                </Form.Item>

                <Form.Item
                    label="Password"
                    name="password"
                    rules={[
                    {
                        required: true,
                        message: '请输入密码',
                    },
                    ]}
                >
                    <Input.Password />
                </Form.Item>

                <Form.Item
                    label="学号"
                    name="num"
                    rules={[
                    {
                        required: true,
                        message: '请输入学号',
                    },
                    ]}
                >
                    <Input/>
                </Form.Item>

                <Form.Item >
                    <Button type="primary" htmlType="submit">
                        注册
                    </Button>
                </Form.Item>
            </Form>
        )
    }
}
